package tcm.com.gistone.database.mapper;

import java.util.List;

import org.apache.ibatis.annotations.*;

import tcm.com.gistone.database.entity.Directory;

@Mapper
public interface DirectoryMapper {
    int deleteByPrimaryKey(Long id);

    int insert(Directory record);

    int insertSelective(Directory record);

    Directory selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Directory record);

    int updateByPrimaryKey(Directory record);

    int insertBatch(List<Directory> list);

    @Select("select * from tb_directory where book_id = #{bookId}")
    @ResultMap("tcm.com.gistone.database.mapper.DirectoryMapper.BaseResultMap")
    List<Directory> selectByBookId(Long bookId);

    /*查询子节点*/
    @Select("select * from tb_directory where parent_id = #{pId} and id != #{pId}")
    @ResultMap("tcm.com.gistone.database.mapper.DirectoryMapper.BaseResultMap")
    List<Directory> selectByParentId(Long pId);

    /*按目录级别查询*/
    @Select("select * from tb_directory where book_id = #{bookId} and level = #{level}")
    @ResultMap("tcm.com.gistone.database.mapper.DirectoryMapper.BaseResultMap")
    List<Directory> selectByBookIdAndLevel(@Param("bookId") Long bookId, @Param("level") int level);

    /*查询一条记录*/
    @Select("select * from tb_directory where book_id = #{bookId} and level = #{level} and name = #{name}")
    @ResultMap("tcm.com.gistone.database.mapper.DirectoryMapper.BaseResultMap")
    Directory selectOne(@Param("bookId") Long bookId, @Param("level") int level, @Param("name") String name);

    /*根据名称查找*/
    @Select("select id from tb_directory where book_id = #{bookId} and name = #{name}")
    List<Long> selectByName(@Param("name") String name, @Param("bookId") long bookId);

    /*根据名称查找*/
    @Select("select * from tb_directory where book_id = #{bookId} and name = #{name}")
    @ResultMap("tcm.com.gistone.database.mapper.DirectoryMapper.BaseResultMap")
    List<Directory> selectDirectoryByName(@Param("name") String name, @Param("bookId") long bookId);
}